package com.lagou.edu.configuration;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @description: 限流
 */

@Configuration
@Slf4j
public class KeyResolverConfiguration {
    /**
     * 基于ip
     * @return
     */
    @Bean
    public KeyResolver IpKeyResolver(){
        return exchange -> {
            String hostName = exchange.getRequest().getRemoteAddress().getAddress().getHostName();
            log.info("hostName:" + hostName);
            return Mono.just(hostName);
        };
    }
}
